package com.atguigu.cloud.controller;

import com.atguigu.cloud.dto.DocumentDto;
import com.atguigu.cloud.dto.UserDTO;
import com.atguigu.cloud.entities.User;
import com.atguigu.cloud.feign.DocumentFeign;
import com.atguigu.cloud.result.Result;
import com.atguigu.cloud.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用戶表
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("getUserList")
    public Result<List<User>> getUserList() {
        if (true)throw new RuntimeException("自定义错误测试");
        return Result.success(userService.list());
    }

    @RequestMapping("getUserPage")
    public Page<UserDTO> getUserPage(UserDTO userDTO) {
        return userService.getUserPage(userDTO,new Page<>());
    }


    @Autowired
    private DocumentFeign documentFeign;

    @RequestMapping("getDocumentList")
    public List<DocumentDto> getDocumentList() {
        return documentFeign.getDocumentList();
    }
}
